
#include "S_3_FanControl_doSet.h"
//#include "string.h"
#include "mi_iid_define.h"
#include "spec.h"
#include "main.h"
#include "section1_set_func.h"

static void P_3_2_FanLevel_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_NUMBER)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // 简单判断数据取值范围是否合法，如果不合法，返回代码: OPERATION_ERROR_VALUE
    if (o->value.data.number.value.integerValue < 0 || o->value.data.number.value.integerValue > 8)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}
	
	if((GetAirMode() == DEHUMIDIFYMODE) && (GetCustomizeSetWindFlag() == SH_RESET))
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.number.value.integerValue;

		LOG_INFO("%s, %ld\r\n",__func__,o->value.data.number.value.integerValue);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
	
		//风速设置
		CloudSetting(FAN_SET,o->value.data.number.value.integerValue,0);
		
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_2_FanLevel_doChange_notify(o->value.data.number.value.integerValue);

    return;
}

static void P_3_3_HorizontalSwing_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_BOOLEAN)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}
	
	if(Get3DPanelFuncFlag() == SH_RESET)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}		
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.boolean.value;
	
	LOG_INFO("%s, %d\r\n",__func__,o->value.data.boolean.value);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
  
	CloudSetting(LEFTRIGHTSWING_SET,o->value.data.boolean.value,0);		
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_3_HorizontalSwing_doChange_notify(o->value.data.boolean.value);

    return;
}

static void P_3_4_VerticalSwing_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_BOOLEAN)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}

	if(Get3DPanelFuncFlag() == SH_RESET)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}			
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.boolean.value;

	LOG_INFO("%s, %d\r\n",__func__,o->value.data.boolean.value);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
    
	CloudSetting(UPDOWNSWING_SET,o->value.data.boolean.value,0);	
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_4_VerticalSwing_doChange_notify(o->value.data.boolean.value);

    return;
}

static void P_3_24_WindSensation_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_BOOLEAN)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}

	if(Get3DPanelFuncFlag() == SH_RESET)//是否有3D面板
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}		
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.boolean.value;

	LOG_INFO("%s, %d\r\n",__func__,o->value.data.boolean.value);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
    
	
	
    return;
}



static void P_3_25_VerticalPosition_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_NUMBER)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // 简单判断数据取值范围是否合法，如果不合法，返回代码: OPERATION_ERROR_VALUE
    if (o->value.data.number.value.integerValue < 0 || o->value.data.number.value.integerValue > 5)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}

	if(Get3DPanelFuncFlag() == SH_RESET)//是否有3D面板
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}	
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.number.value.integerValue;

	LOG_INFO("%s, %ld\r\n",__func__,o->value.data.number.value.integerValue);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
	
	CloudSetting(UPDOWNSWINGPOSITION_SET,o->value.data.number.value.integerValue,0);
    
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_25_VerticalPosition_doChange_notify(o->value.data.number.value.integerValue);

    return;
}

static void P_3_26_HorizontalPosition_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_NUMBER)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // 简单判断数据取值范围是否合法，如果不合法，返回代码: OPERATION_ERROR_VALUE
    if (o->value.data.number.value.integerValue < 0 || o->value.data.number.value.integerValue > 5)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}

	if(Get3DPanelFuncFlag() == SH_RESET)//是否有3D面板
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}	
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.number.value.integerValue;

	LOG_INFO("%s, %ld\r\n",__func__,o->value.data.number.value.integerValue);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
    
	CloudSetting(LEFTRIGHTSWINGPOSITION_SET,o->value.data.number.value.integerValue,0);	
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_26_HorizontalPosition_doChange_notify(o->value.data.number.value.integerValue);

    return;
}

static void P_3_11_WindDirection_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_NUMBER)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // 简单判断数据取值范围是否合法，如果不合法，返回代码: OPERATION_ERROR_VALUE
    if (o->value.data.number.value.integerValue < 0 || o->value.data.number.value.integerValue > 7)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSwitchState() == SWITCH_OFF) 
	{
		o->code = OPERATION_ERROR_VALUE;
		return;
	}
	
	if(o->value.data.number.value.integerValue == 3)
	{
		if(GetAirMode() == HOTMODE || GetAirMode() == DEHUMIDIFYMODE || GetAirMode() == FANMODE)
		{
			o->code = OPERATION_ERROR_VALUE;
			return;
		}
	}

	if(Get3DPanelFuncFlag() == SH_RESET)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;		
	}		
	
	if(o->value.data.number.value.integerValue == 6)
	{
		if(GetAirMode() == DEHUMIDIFYMODE)
		{
			if(GetDrySwingFunc() == false)
			{
				o->code = OPERATION_ERROR_VALUE;
				return;
			}
		}
	}
	
	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.number.value.integerValue;

	LOG_INFO("%s, %ld\r\n",__func__,o->value.data.number.value.integerValue);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
    
	if((4 == o->value.data.number.value.integerValue) || (11 == o->value.data.number.value.integerValue))
	{
		o->value.data.number.value.integerValue = 7;
	}
	
	A0D_3_11_Set(o->value.data.number.value.integerValue);	
//	BeepStart();
		
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_3_11_WindDirection_doChange_notify(o->value.data.number.value.integerValue);

    return;
}

void S_3_FanControl_doSet(property_operation_t *o)
{
    switch (o->piid)
    {
        case PIID_3_2_FanLevel:
            P_3_2_FanLevel_doSet(o);
            break;

        case PIID_3_3_HorizontalSwing:
            P_3_3_HorizontalSwing_doSet(o);
            break;

        case PIID_3_4_VerticalSwing:
            P_3_4_VerticalSwing_doSet(o);
            break;

		case PIID_3_11_WindDirection:
            P_3_11_WindDirection_doSet(o);
            break;
		
		case PIID_3_24_WindSensation:
            P_3_24_WindSensation_doSet(o);
            break;
		
        case PIID_3_25_VerticalPosition:
            P_3_25_VerticalPosition_doSet(o);
            break;

        case PIID_3_26_HorizontalPosition:
            P_3_26_HorizontalPosition_doSet(o);
            break;

        default:
            o->code = OPERATION_ERROR_VALUE;
            break;
    }
}
